home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_02 / allison / max1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-30  |  374 b   |  28 lines

  1. LISTING 1 - Finds the largest of n integers
  2. /* max1.c */
  3. #include <stdio.h>
  4.  
  5. int maxn(size_t n,...)
  6. {
  7.     int x;
  8.     int *p = (int *) (&n + 1);
  9.     int m = *p;
  10.  
  11.     while (--n)
  12.     {
  13.         x = *++p;
  14.         if (x > m)
  15.             m = x;
  16.     }
  17.     return m;
  18. }
  19.  
  20. main()
  21. {
  22.     printf("max = %d\n",maxn(3,1,3,2));
  23.     return 0;
  24. }
  25.  
  26. /* Output:
  27. max = 3
  28.